<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/1/8
 * Time: 9:43
 */

namespace common\sources\read\smscode;

use common\models\craftsman\SmsCode;

class SmsCodeAccess implements ISmsCodeAccess
{
    public function getPhoneCode($data)
    {
        return SmsCode::find()
            ->where(['phone' => $data['phone']])
            ->orderBy("sendtime desc")
            ->asArray()
            ->all();
    }

    public function getSms($data)
    {
        // TODO: Implement smsInfo() method.
        return SmsCode::find()
            ->where(['phone' => $data['phone']])
            ->andFilterWhere(['between', 'sendtime', $data['today'], $data['endtoday']])
            ->asArray()
            ->count();
    }

    public function getSmsCode($data)
    {
        return  SmsCode::find()
                ->select('id,verifycode,sendtime')
                ->where(['phone' => $data['phone'],'type' => $data['type'],'status'=>1])
                ->orderBy('sendtime DESC')
                ->asArray()
                ->one();
    }
}